// pages/home/home.js
const order = ['demo1', 'demo2', 'demo3']
var {new_Arrival,recommend,commodityxq,Homepageby,register} = require('../../utils/util');
// index.js

var {
  Rs
} = require('../../utils/util')
// console.log(Rs);
const app = getApp()
Page({
  data: {
    background: ['/public/images/1.png', '/public/images/1.png', '/public/images/1.png'],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    shoulun: [],
    list: [],
    shop: [],
    page: 0,
    tupian: 'https://img.9lele.com/',
    dopage: true,
    arr: [{
        img: '/public/images/Mac.png',
        title: 'Mac'
      },
      {
        img: '/public/images/ipad.png',
        title: 'ipad'
      },
      {
        img: '/public/images/iPhone.png',
        title: 'iPhone'
      },
      {
        img: '/public/images/watch.png',
        title: 'watch'
      },
      {
        img: '/public/images/MusicAcc.png',
        title: 'Music'
      },
      {
        img: '/public/images/peijian.png',
        title: '配件'
      },
    ],
    arr1: [],
    arr2: []
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },

  onShow: function () {

    // this.setData({
    //   shop:[1,2,3]
    // })
    // console.log(this.data.shop)
    this.getList()
    this.onReachBottom()
  },

  getList() {
    var that = this
    //   this.setData({
    //     shop:1
    // })
    wx.request({
        url: Rs() + '/goods/is_new/1', //仅为示例，并非真实的接口地址

        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          // console.log(res.data)
          that.setData({
            arr1: res.data.data
          })
          console.log(that.data.arr1);
        }
      }),
      wx.request({
        url: Rs() + '/bannerList', //仅为示例，并非真实的接口地址

        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          // console.log(res.data)
          that.setData({
            shoulun: res.data.data
          })
          console.log(that.data.shoulun);
        }
      })
  },

  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  // onPageScroll(obj){
  //   console.log(obj)
  // },
  onReachBottom() {
    var that = this
    let pages = this.data.page + 1
    if (this.data.dopage)
      wx.request({
        url: Rs() + '/goods/is_recommend/0'+pages, //仅为示例，并非真实的接口地址

        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          console.log(res.data)
          let arr = that.data.list
          let arr2 = res.data.data
          if (arr2.length < 1) {
            that.setData({
              dopage: false
            })
          } else {
            arr.push(...arr2)
            that.setData({
              arr2: arr,
              page: pages
            })
          }
          console.log(that.data.list)
        }
      })
  },
  shops() {
    wx.navigateTo({
      url: '/pages/mac/mac',
    })
  },
  xiangqing(e) {
    console.log(e)
    let ids = e.currentTarget.dataset.ids
    console.log(183, ids)
    wx.navigateTo({
      url: '/pages/xiangqing/xiangqing?ids=' + ids,
    })
  },
  lan(datas) {
    let obj = datas.target.dataset.obj
    console.log(datas)
    let arr = this.data.shop
    console.log(arr)
    arr[obj].original_img = "/public/images/1.png"
    this.setData({
      shop: arr
    })
  }
})